package com.corner.ui.activity;

import android.content.Intent;
import android.view.View;
import android.widget.ListView;

import com.corner.R;
import com.corner.model.db.User;
import com.corner.presenter.imp.SelectContactPresenter;
import com.corner.ui.adapter.SelectContactAdapter;
import com.corner.ui.base.BaseActivity;
import com.corner.ui.view.ISelectContactView;
import com.corner.utils.AppManager;
import com.corner.utils.view.FindView;
import com.corner.utils.view.MainActionBar;

import java.util.List;

/**
 * Created by Administrator on 2015/7/21，23.29.
 * 描述：
 */
public class SelectContactActivity extends BaseActivity<SelectContactPresenter> implements ISelectContactView, View.OnClickListener {
    private MainActionBar actionBar;
    @FindView(R.id.lv_contact)
    private ListView lvContact;

    private View divider;
    private SelectContactAdapter adapter;
    private List<User> users;

    @Override
    protected SelectContactPresenter createP() {
        return new SelectContactPresenter();
    }

    @Override
    protected void setOnClick() {
        actionBar.btnLeft.setOnClickListener(this);
    }

    @Override
    public void initView() {
        super.initView();
        actionBar = new MainActionBar(this);
        actionBar.initActionBarButton();
        actionBar.btnLeft.setVisibility(View.VISIBLE);
        actionBar.btnLeft.setText(getString(R.string.activity_select_contact_back_notice));
        divider = View.inflate(this, R.layout.view_lv_select_contact_header, null);
        lvContact.addHeaderView(divider);
    }

    @Override
    protected void initData() {
        presenter.requestUsers();

    }

    @Override
    public void setContentView() {
        setContentView(R.layout.activity_share_select_contact);
    }

    @Override
    public void showContact(List<User> users) {
        this.users = users;
        adapter = new SelectContactAdapter(this, this.users);
        lvContact.setAdapter(adapter);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_actionbar_left:
                AppManager.getInstance().finishActivity(this);
        }
    }


    /**
     * 选中了user
     *
     * @param user
     */
    public void selectUser(User user) {
        Intent intent = getIntent();
        intent.setClass(this, ChatActivity.class);
        intent.putExtra(ChatActivity.USER_ID_IN_LONG, user.getId());
        startActivity(intent);
        AppManager.getInstance().finishActivity(this);
    }
}
